package StackOrQueue;

import java.util.Stack;

class isValid {
    public  static boolean isValid(String s) {
        Stack<Character> stack = new Stack<>();
        char[] chars = s.toCharArray();
        int n = chars.length;
        for (int i = 0; i <n; i++) {
            switch (chars[i]){
                case '{':
                case '(':
                case '[':
                    stack.push(chars[i]);
                    break;
                case '}':
                    if(stack.isEmpty()||stack.pop()!='{')
                        return false;
                    break;
                case ')':
                    if(stack.isEmpty()||stack.pop()!='(')
                        return false;
                    break;
                case ']':
                    if(stack.isEmpty()||stack.pop()!='[')
                        return false;
                    break;
            }
        }
        return true;

    }

    public static void main(String[] args) {
//        System.out.println(isValid(new String("{}()[{]")));
        String s = " d + d";
        System.out.println(s.replace(" ",""));
    }
}
